<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>${inviteSource}·数据工厂</title>
    <link href="${pageContext.request.contextPath }/img/webLogoIcon.png"
          rel="shortcut icon">
    <link href="${pageContext.request.contextPath }/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/font-awesome.css"
          rel="stylesheet">

    <link href="${pageContext.request.contextPath }/css/animate.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/style.css"
          rel="stylesheet">

    <!-- FooTable -->
    <link href="${pageContext.request.contextPath }/css/footable.core.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/datepicker3.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/mypage.css"
          rel="stylesheet">
</head>

<body>

<div id="wrapper">

    <nav class="navbar-default navbar-static-side" role="navigation">

        <jsp:include page="../components/left.jsp" flush="true"/>
    </nav>

    <div id="page-wrapper" class="gray-bg">
        <div class="row border-bottom m-b-20">
            <jsp:include page="../components/head.jsp" flush="true"/>
        </div>
        <div class="row wrapper border-bottom white-bg page-heading">
            <div class="col-lg-9">
                <h2>${inviteSource}</h2>
                <ol class="breadcrumb">
                    <li class="nav-main1"><a
                            href="${pageContext.request.contextPath}/admin/tosystem_overview">主页</a>
                    </li>
                    <li class="nav-main2"><a id="navigation1" href="#">招聘数据</a></li>
                    <li class="active"><a>${inviteSource}</a></li>
                </ol>
            </div>
        </div>

        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                <div class="ibox float-e-margins barcontent" id="barcontent"></div>
                    <div class="ibox float-e-margins">

<!--                         <div class="ibox-content1" style="display: flex; padding: 15px 0 15px 40px;"> -->
<!--                             下拉框 -->
<!--                             <div class="row"> -->
<!--                                 <div class="col-sm-5 m-b-xs" style="width:300px"> -->
<!--                                     省:<select id="province" class="input-sm form-control input-s-sm inline" -->
<!--                                               style="width:90px;height:35px;margin-right:10px" -->
<!--                                               onchange="provinceChange()"> -->
<!--                                     <option value="">全部</option> -->
<%--                                     <option value="1">北京</option> --%>
<!--                                 </select> -->

<!--                                     市:<select id="city" class="input-sm form-control input-s-sm inline" -->
<!--                                               style="width:90px;height:35px;margin-right:10px" onchange="cityChange()"> -->
<!--                                     <option value="">全部</option> -->
<!--                                 </select> -->
<!--                                 </div> -->
<%--                                 <div class="col-sm-4 m-b-xs"></div> --%>
<%--                                 <div class="col-sm-3"></div> --%>
<!--                             </div> -->

<!--                             <div class="input-group" style="width:250px;margin-right:20px"> -->
<!--                                 <input id="keywords" type="text" class="form-control"> -->
<!--                                 <div class="input-group-btn"> -->
<!--                                     <button tabindex="-1" class="btn btn-white" type="button" onclick="searchBidding()"> -->
<!--                                         搜索 -->
<!--                                     </button> -->
<!--                                     <button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button" -->
<!--                                             aria-expanded="false" style="height:34px"><span class="caret"></span> -->
<!--                                     </button> -->
<!--                                     <ul class="dropdown-menu pull-right" id="searchType"> -->
<!--                                         <li data-id="2"><a>全部</a></li> -->
<!--                                         <li data-id="0"><a>标题</a></li> -->
<!--                                         <li data-id="1"><a>正文</a></li> -->
<!--                                     </ul> -->
<!--                                 </div> -->
<!--                             </div> -->
<!--                         </div> -->

                        <div class="ibox-content">
	                         <div class="input-select" style="margin-bottom: 20px">
		                               		<div class="input-selectbox">
	                                            <button data-toggle="dropdown" class="btn btn-primary dropdown-toggle" type="button"  aria-expanded="false">
	                                            <i class="fa fa-bars"></i>
	                                            <span id="inputSelected">全部</span></button>
	                                            <ul class="dropdown-menu" id="selectlist">
	                                            	<li><a onclick="setselect(this)">全部</a></li>
	                                                <li><a onclick="setselect(this)">公司</a></li>
	                                                <li><a onclick="setselect(this)">职位</a></li>
	                                                <li><a onclick="setselect(this)">岗位描述</a></li>
	                                            </ul>
		                                        <input  id="keywords" type="text" class="form-control" style="width:440px;padding-right: 42px;">
		                                        <i id="gosearch" class="fa fa-search cursearch" onclick="searchBidding()"></i>
		                                    </div>
	                              </div>
                            <div class="table-responsive">
                                <table class="table">
                                    <thead>
                                    <tr style="background:#f5f5f6">
                                            <th>职位</th>
                                            <th>公司</th>
                                            <th>地区</th>
                                            <th>招聘人数</th>
                                            <th>发布时间</th>
                                    </tr>
                                    </thead>
                                    <tbody id="tbody">
                                    <c:forEach items="${invites.inviteList}" var="invite">
                                        <tr>
                                          
                                            <td>
                                                <small>${invite.invite_source}</small>
                                            </td>
                                            <td>
                                                <small>${invite.company_name}</small>
                                            </td>
                                            <td>${invite.invite_city}</td>
                                                <%--<td><c:if test="${invite.job_type==0}">--%>
                                                <%--主营岗--%>
                                                <%--</c:if> <c:if test="${invite.job_type!=0}">--%>
                                                <%--其他--%>
                                                <%--</c:if></td>--%>
                                            <td><a target="_blank"
                                                   href="${pageContext.request.contextPath}/invite/inviteDetails?record_id=${invite.record_id}">${invite.invite_title}<a>
                                            </td>
                                            <td><c:if test="${invite.edu_level==0}">
                                                学历不限
                                            </c:if> <c:if test="${invite.edu_level==1}">
                                                初中及以下
                                            </c:if> <c:if test="${invite.edu_level==2}">
                                                初中
                                            </c:if> <c:if test="${invite.edu_level==3}">
                                                中专/中技/高中
                                            </c:if> <c:if test="${invite.edu_level==4}">
                                                大专
                                            </c:if> <c:if test="${invite.edu_level==5}">
                                                本科
                                            </c:if> <c:if test="${invite.edu_level==6}">
                                                硕士
                                            </c:if> <c:if test="${invite.edu_level==7}">
                                                博士
                                            </c:if> <c:if test="${invite.edu_level==8}">
                                                MBA/EMBA
                                            </c:if></td>
                                            <td>${invite.invite_count}</td>
                                            <td>${invite.min_salary}-${invite.max_salary}元/月</td>
                                                <%--<td>--%>
                                                <%--<c:if test="${invite.stop_inviteflag==0}">--%>
                                                <%--是--%>
                                                <%--</c:if> --%>
                                                <%----%>
                                                <%--<c:if test="${invite.stop_inviteflag!=0}">--%>
                                                <%--否--%>
                                                <%--</c:if>--%>
                                                <%--</td>--%>
                                                <%--<td>--%>
                                                <%--<c:if test="${invite.add_invitejob==0}">--%>
                                                <%--否--%>
                                                <%--</c:if>--%>
                                                <%--<c:if test="${invite.add_invitejob!=0}">--%>
                                                <%--是--%>
                                                <%--</c:if>--%>
                                                <%--</td>--%>
                                                <td><span id="updateTime0">${invite.push_time}</span></td>
                                        </tr>
                                    </c:forEach>
                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <td colspan="7" id="fenyes">
                                            <%--  <c:if test="${invites.pageCount>0}"> --%>
                                            <div class="box" id="box" style="float: right;"></div>
                                            <%--   </c:if> --%>
                                        </td>
                                    </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <jsp:include page="../components/footer.jsp" flush="true"/>
    </div>
</div>


<!-- Mainly scripts -->
<script src="${pageContext.request.contextPath }/js/jquery-2.1.1.js"></script>
<script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
<script
        src="${pageContext.request.contextPath }/js/jquery.metisMenu.js"></script>
<script
        src="${pageContext.request.contextPath }/js/jquery.slimscroll.min.js"></script>

<!-- Custom and plugin javascript -->
<script src="${pageContext.request.contextPath }/js/inspinia.js"></script>
<script src="${pageContext.request.contextPath }/js/pace.min.js"></script>


<!-- FooTable -->
<script src="${pageContext.request.contextPath }/js/footable.all.min.js"></script>
<script src="${pageContext.request.contextPath}/js/mypage.js"></script>

<script
        src="${pageContext.request.contextPath }/js/plugins/toastr/toastr.min.js"></script>

<!-- Page-Level Scripts -->
	<script src="${pageContext.request.contextPath}/js/anychart-base.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/userCustom.js"></script>
	<script>
var data = 
	[
	     ['医疗化工', '4054'],
	     ['汽车制造', '3410'],
	     ['房地产', '6610'],
	     ['金融', '7130'],
	     ['IT', '8000'],
	     ['消费品', '4760'],
	     ['物流', '3670'],
	     ['旅游', '2210'],
	     ['服务业', '6980'],
	     ['教育', '3210'],
	     ['销售', '5210'],
	     ['传媒', '4210'],
	     ['其他', '2310']
		]
createbar("barcontent","${inviteSource}行业招聘分布",data)
    let searchType = 0;
    $(document).ready(function () {
//        sendData(1);
        initProvice();
        let data = getreqData();
        sendData(data);
    });
    
    function setselect(el){
    	$('#inputSelected').html(el.innerText)
    	switch (el.innerText) {
		case "全部":
			searchType=2
			break;
		case "公司":
			searchType=3
			break;
		case "职位":
			searchType=0
			break;
		case "岗位描述":
			searchType=1
			break;
		}
    }

    // 初始化省份信息
    function initProvice() {
        $.ajax({
            url: "${pageContext.request.contextPath}/invite/getProviceAsyn",
            type: "get",
            dataType: "json",
            data: {},
            success: function (res) {
                console.log("省份数据请求成功");
                groupProvince(res);
            },
            error: function (err) {
                console.log("省份数据请求失败")
                console.log(err);
            }
        });
    }

    // 组装省份数据
    function groupProvince(res) {
        let code = res.code;
        let data = res.data;
        let provinceStr = '';
        if (code == "200") {
            if (data.length > 0) {
                for (let i = 0; i <= data.length; i++) {
                    let provincestr = '';
                    if (i == 0) {
                        provincestr = '<option selected" value="">全部</option>';
                    } else {
                        let dataObj = data[i - 1];
                        let key = dataObj.key;
                        let doc_count = dataObj.doc_count;
                        provincestr = '<option value="' + key + '">' + key + '</option>';
                    }
                    provinceStr += provincestr;
                }
            } else {
                provinceStr = '<option selected value="">全部</option>';
            }
        } else {
            provinceStr = '<option selected value="">全部</option>';
        }
        $("#province").html(provinceStr);
    }

    // 异步获取省份信息
    function provinceChange() {
        let proviceName = $("#province option:selected").val();  // 省名称
        initCityInfo(proviceName);
        let data = getreqData();
        sendData(data);
    }

    // 初始化城市信息
    function initCityInfo(proviceName) {
        if (proviceName != "") {
            $.ajax({
                url: "${pageContext.request.contextPath}/invite/getCityAsyn",
                type: "get",
                dataType: "json",
                data: {
                    "province": proviceName
                },
                success: function (res) {
                    console.log("城市数据请求成功");
                    let code = res.code;
                    let data = res.data;
                    let cityStr = '';
                    if (code == "200") {
                        if (data.length > 0) {
                            for (let i = 0; i <= data.length; i++) {
                                let citystr = '';
                                if (i == 0) {
                                    citystr = '<option selected" value="">全部</option>';
                                } else {
                                    let dataObj = data[i - 1];
                                    let key = dataObj.key;
                                    let doc_count = dataObj.doc_count;
                                    citystr = '<option value="' + key + '">' + key + '</option>';
                                }
                                cityStr += citystr;
                            }
                        } else {
                            cityStr = '<option selected value="">全部</option>';
                        }
                    } else {
                        cityStr = '<option selected value="">全部</option>';
                    }
                    $("#city").html(cityStr);
                },
                error: function (err) {
                    console.log("城市数据请求失败")
                    console.log(err);
                }
            });
        } else {
            $("#city").html('<option selected value="">全部</option>');
        }
    }

    // 异步获取城市信息
    function cityChange() {
        let data = getreqData();
        sendData(data);
    }

    // 点击切换搜索类型
    $("#searchType li").click(function () {
        searchType = $(this).attr("data-id");
    });

    // 获取数据
    function getreqData() {
        let keywords = $("#keywords").val(); // 关键词
        let data = {};
        data.searchkeywrord = keywords;
        data.searchtype = searchType.toString();
        let inviteSource = "${inviteSource}";
        data.page = "1";
        data.jobsorigin = inviteSource;
        return data;
    }

    // 点击搜索数据
    function searchBidding() {
        let data = getreqData();
        sendData(data);
    }

    function sendData(data) {
        let inviteSource1 = "${inviteSource}";
        let searchText1 = $("#searchText").val();
        let searchType1 = $("#searchType option:selected").val();
        $.ajax({
            url: "${pageContext.request.contextPath}/invite/inviteList",
            type: "POST",
            dataType: "json",
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify(data),
            success: function (res) {
                console.log("请求成功")
                groupData(res);
            },
            error: function (err) {
                console.log("请求失败")
                console.log(err)
            }
        })
    }

    <%--function sendData(pagenum) {--%>
    <%--let inviteSource1 = "${inviteSource}";--%>
    <%--let searchText1 = $("#searchText").val();--%>
    <%--let searchType1 = $("#searchType option:selected").val();--%>
    <%--$.ajax({--%>
    <%--url: "${pageContext.request.contextPath}/invite/inviteList",--%>
    <%--type: "get",--%>
    <%--dataType: "json",--%>
    <%--data: {--%>
    <%--inviteSource: inviteSource1,--%>
    <%--searchText: searchText1,--%>
    <%--searchType: searchType1,--%>
    <%--pageNum: pagenum--%>
    <%--},--%>
    <%--success: function (res) {--%>
    <%--console.log("请求成功")--%>
    <%--groupData(res);--%>
    <%--},--%>
    <%--error: function (err) {--%>
    <%--console.log("请求失败")--%>
    <%--console.log(err)--%>
    <%--}--%>
    <%--})--%>
    <%--}--%>

    function sendSources() {
        $.ajax({
            url: "${pageContext.request.contextPath}/invite/sourceList",
            type: "get",
            dataType: "json",
            data: {},
            success: function (res) {
                console.log("请求成功")
                groupSourceData(res);
            },
            error: function (err) {
                console.log("请求失败")
                console.log(err)
            }
        })
    }

    function groupSourceData(res) {
        let sourceStr = "";
        for (let i = 0; i <= res.length; i++) {
            if (i == 0) {
                sourceStr = "<option >全部</option>";
            } else {
                sourceStr += "<option>" + res[i - 1] + "</option>";
            }
        }
        $("#sourceType").html(sourceStr);
        sendData(1);
    }

    // 组装数据
    function groupData(res) {
        res = JSON.parse(res);
        let source = res.source;
        let totalCount = res.totalCount;
        let pageNum = res.pageNum;
        let pageCount = res.pageCount;
        let inviteList = res.inviteList;
        if (pageCount > 500) {
            pageCount = 500;
        }
        paging(totalCount, pageCount, pageNum);
        let inviteList1 = '';
        if (inviteList.length > 0) {
            for (let i = 0; i < inviteList.length; i++) {
                let inviteObj = inviteList[i];
                let job_type = inviteObj.job_type;
                let min_salary = inviteObj.min_salary;
                let invite_source = inviteObj.invite_source;
                let add_invitejob = inviteObj.add_invitejob;
                let max_salary = inviteObj.max_salary;
                let invite_count = inviteObj.invite_count;
                let invite_city = inviteObj.invite_city;
                let push_time = inviteObj.push_time;
                push_time = push_time.substring(0, 10);
                let stop_inviteflag = inviteObj.stop_inviteflag;
                let edu_level = inviteObj.edu_level;
                let invite_title = inviteObj.invite_title;
                let company_name = inviteObj.company_name;
                let record_id = inviteObj.record_id;

                if (edu_level == 0) {
                    edu_level = "学历不限";
                } else if (edu_level == 1) {
                    edu_level = "初中及以下";
                } else if (edu_level == 2) {
                    edu_level = "初中";
                } else if (edu_level == 3) {
                    edu_level = "中专/中技/高中";
                } else if (edu_level == 4) {
                    edu_level = "大专";
                } else if (edu_level == 5) {
                    edu_level = "本科";
                } else if (edu_level == 6) {
                    edu_level = "硕士";
                } else if (edu_level == 7) {
                    edu_level = "博士";
                } else if (edu_level == 8) {
                    edu_level = "MBA/EMBA";
                }

//            if (stop_inviteflag == "1") {
//                stop_inviteflag = "否"
//            } else {
//                stop_inviteflag = "是"
//            }
//
//            if (add_invitejob == "1") {
//                add_invitejob = "是"
//            } else {
//                add_invitejob = "否"
//            }

                if (job_type == "0") {
                    job_type = "主营岗位"
                } else {
                    job_type = "其他"
                }

                <%--let str0 = '<tr><td>' + push_time + '</td><td>' + invite_source + '</td><td>' + company_name + '</td><td>' + invite_city + '</td>' +--%>
                    <%--'<td><a  target="_blank" href = "${pageContext.request.contextPath}/invite/inviteDetails?record_id=' + record_id + '">' + invite_title + '</a></td><td>' + edu_level + '</td><td>' + invite_count + '</td><td>' + min_salary + '-' + max_salary + '元/月</td>' +--%>
                    <%--'</tr>';--%>
                let str0 = '<tr><td><a  target="_blank" href = "${pageContext.request.contextPath}/invite/inviteDetails?record_id=' + record_id + '">' + invite_title + '</a></td><td>' + company_name + '</td>' +
                    '<td>' +invite_city  + '</td><td>' + invite_count + '</td><td>' + push_time + '</td></tr>';
                inviteList1 += str0;
            }
        } else {
            inviteList1 = '<tr><td colspan="5" style="text-align: center">暂无数据，换个搜索词试试！</td></tr>';
            $('#box').html('')
        }
        $("#tbody").html(inviteList1);
    }

    function paging(totalData, totalPage, pagenum) {
        $('#box').paging({
            initPageNo: pagenum, // 初始页码
            totalPages: totalPage, //总页数
            totalCount: '合计' + totalData + '条数据', // 条目总数
            slideSpeed: 600, // 缓动速度 单位毫秒
            jump: true, //是否支持跳转
            callback: function (page) {
                // 回调函数
            }
        });
    }

    function JumpToPage(pagenum) {
        if (pagenum > 500) {
            pagenum = 500
        }
        let data = getreqData();
        data.page = pagenum.toString();
        sendData(data);
    }
</script>

<!-- FooTable -->
</body>

</html>
